<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.folder.php 434 2014-01-19 11:47:24Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 434 $
* 	zuletzt geaendert von:	$Author: $
* 	Datum:					$Date: 2014-01-19 11:47:24 +0000 (Sun, 19 Jan 2014) $
*
* 	http://www.itdotmedia.de
*
*
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
* 	(c) 2011     SEO:mercari by Siekiera Media
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);

$xajax->registerFunction('getFolderChilds');

function getFolderChilds($parent_path = '') {
	global $db;
	$ajax = new xajaxResponse();
	if ($parent_path == '') $parent_path = DS;
  $parent_path_arr = array_values(array_filter(explode(DS, $parent_path)));

  $parent_path = DIR_FS_ACCOUNT_ROOT;
  if (count($parent_path_arr) > 0) {
    if ($parent_path_arr[count($parent_path_arr)-1] == '..')
      $parent_path_arr = array_slice($parent_path_arr, 0, -2);

    foreach($parent_path_arr as $folder) {
      if(@is_dir(implode(DS, array($parent_path, $folder))))
        $parent_path = implode(DS, array($parent_path, $folder));
      else
        break;
    }
  }
  $folder_items = scandir($parent_path);
  foreach($folder_items as $k => &$v) {
    if(!@is_dir($parent_path.DS.$v))
      $v = '';
    else if($v == '.')
      $v = '';
    else if($v == '..' && count($parent_path_arr) == 0)
      $v = '';
    else
      $v = str_replace(DIR_FS_ACCOUNT_ROOT, '', $parent_path.DS.$v);
  }
  $folder_items = array_filter(array_values($folder_items));
	$ajax->call('refreshFolderList', json_encode($folder_items));
	return $ajax;
}
